package org.common.controller;

import lombok.extern.slf4j.Slf4j;
import org.common.annotation.LogInfoAnnotation;
import org.common.annotation.RedisLimitAnnotation;
import org.common.response.ResultData;
import org.common.strategy1.Factory;
import org.common.strategy1.StrategyFactory;
import org.common.strategy2.AbstractStrategyFactory;
import org.common.strategy2.Factory2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: TestController
 * Package: org.common.controller
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/7/19 - 11:17
 * @Version: v1.0
 */
@Slf4j
@RestController
public class TestController {

    @GetMapping("/test")
    @LogInfoAnnotation
    public ResultData test(@RequestParam("name") String name){
        log.info("请求参数为：{}",name);
        return ResultData.success(name);
    }

    @GetMapping("/list/{pageNo}/{pageSize}")
    @LogInfoAnnotation
    public ResultData list(@PathVariable("pageNo") Integer pageNo,
                           @PathVariable("pageSize") Integer pageSize){

        log.info("请求参数为：{},{}",pageNo,pageSize);
        return ResultData.success("pageNo" + pageNo + "," + "pageSize" + pageSize);
    }

    @GetMapping("/limit")
    @RedisLimitAnnotation(key = "limit",maxRestrictions = 4, expireTime = 10,message = "请求次数过多，请稍后再试！")
    public ResultData limit(){
        return ResultData.success();
    }

    @GetMapping("/pay")
    public ResultData pay(@RequestParam("payType") String payType){
        // 获取策略对象
        StrategyFactory invokeStrategy = Factory.getInvokeStrategy(payType);
        // 执行策略
        invokeStrategy.pay(payType);
        return ResultData.success();
    }

    @GetMapping("/pay2")
    public ResultData pay2(@RequestParam("payType") String payType){
        // 获取策略对象
        AbstractStrategyFactory invokeStrategy = Factory2.getInvokeStrategy(payType);
        // 执行策略
        invokeStrategy.pay(payType);
        invokeStrategy.payMethod(payType);
        return ResultData.success();
    }
}
